import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import( '@/views/LoginView.vue')
  },
  {
    path: '/home',
    name: 'home',
    redirect: '/index',
    component: () => import( '@/views/home/IndexView.vue'),
    children:[
      {
        path: '/index',
        name: 'index',
        meta:{title:'首页'},
        component: () => import( '@/views/home/index/indexView.vue')
      },
      {
        path: '/user',
        name: 'user',
        meta:{title:'权限管理'},
        component: () => import( '@/views/home/user/indexView.vue'),
        children:[
          {
            path: '/user/list',
            name: 'userList',
            meta:{title:'用户管理'},
            component: () => import( '@/views/home/user/indexViewList.vue')
          },
          {
            path: '/role/list',
            name: 'roleList',
            meta:{title:'角色管理'},
            component: () => import( '@/views/home/role/roleViewList.vue')
          },
          {
            path: '/menu/list',
            name: 'menuList',
            meta:{title:'菜单管理'},
            component: () => import( '@/views/home/menu/indexView.vue')
          }
        ]
      },
      {
        path: '/sms',
        name: 'sms',
        meta:{title:'信息管理'},
        component: () => import( '@/views/home/menu/indexView.vue')
        
      }
  
    ]
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


const whiteList = ['login']

/**路由拦截 判断是否有token是有值，如果没有值则。 */
router.beforeEach(
  function(to,from,next){
    let user = sessionStorage.getItem('user');
    if(!sessionStorage.getItem('user')){
      if(to.path != '/login'){
        next('/login')
      }
    };
    next();
  }
)


export default router
